home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Apple Guide / Engineering / APISample / APISampleMPW / TApplication / TApplication.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-23  |  5.6 KB  |  143 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    TApplication
  8. #
  9. #    TApplication.h    -    C++ source
  10. #
  11. #    Copyright © 1991 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.20                    10/91
  16. #            1.10                     07/89
  17. #            1.00                     04/89
  18. #
  19. #    Components:
  20. #            TApplicationCommon.h    July 9, 1989
  21. #            TApplication.h            July 9, 1989
  22. #            TApplication.cp            July 9, 1989
  23. #            TApplication.r            July 9, 1989
  24. #            TDocument.h                July 9, 1989
  25. #
  26. #    CPlusAppLib is a rudimentary application framework
  27. #    for C++. The applications CPlusShapesApp and CPlusTESample
  28. #    are built using CPlusAppLib.
  29. #
  30. ------------------------------------------------------------------------------*/
  31.  
  32. #ifndef TAPPLICATION_H
  33. #define TAPPLICATION_H
  34.  
  35. // Include necessary interface files
  36. #include <Types.h>
  37. #include <Desk.h>
  38. #include <Events.h>
  39. #include <OSUtils.h>
  40.  
  41. // we need definitions of our base classes
  42. // Includes are relative to the including file, not the included file.
  43. // If we are building our main, then the TApplication and TDocument
  44. // header folders are enclosed in our folder.
  45. // Otherwise, we are building TApplication and within that folder.
  46. #ifdef __UMAIN__
  47.                                     // use the local version. If you make changes
  48.                                     // that you've debugged and want other files
  49.                                     // to use, simple copy the header files into
  50.                                     // the C++ Includes folder (don't forget to
  51.                                     // copy the TApplication object library to the C++
  52.                                     // Libraries folder)!
  53.     #include ":TApplication:TApplicationCommon.h"            
  54.     #include ":TDocument:TDocument.h"
  55. #else
  56.     #include "TApplicationCommon.h"
  57.     #include "::TDocument:TDocument.h"
  58. #endif
  59.  
  60. /*
  61.     TApplication:
  62.  
  63.     This is our class which implements a basic Macintosh style program,
  64.     including a MultiFinder-aware event loop. 
  65. */
  66.  
  67. // we derive from handle object to prevent fragmentation
  68. class TApplication : public HandleObject
  69. {
  70.     public:
  71.         //    these member functions can be called by anyone
  72.                     TApplication            ( void );                                        // Our constructor & destructor
  73.             void    EventLoop                ( void );                                        // Call this routine to start event loop running
  74.             inline    TDocumentList* DocList    ( void )        { return fDocList; }            // a utility routine that you may need to use
  75.             Boolean TrapAvailable            ( short tNumber, TrapType tType );                // Is trap implemented???
  76.     
  77.     protected:
  78.         // useful variables
  79.             Boolean            fHaveWaitNextEvent;        // true if we have WaitNextEvent trap
  80.             Boolean            fDone;                    // set to true when we are ready to quit
  81.             EventRecord        fTheEvent;                // our event record
  82.             WindowPtr        fWhichWindow;            // currently active window
  83.             Boolean            fInBackground;            // true if our app is suspended
  84.             Boolean            fWantFrontClicks;        // true if we want front clicks
  85.             RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  86.             TDocument*        fCurDoc;                // currently active document (if any)
  87.             TDocumentList*    fDocList;                // the list of documents
  88.  
  89.         // Returns total stack space required in bytes.
  90.         // Returns 0 by default, which tells the initialization code
  91.         // to use the default stack size.
  92.             virtual long StackNeeded        ( void )     { return 0; }
  93.     
  94.         // Returns total heap space required in bytes.
  95.         // Returns 0 by default, which tells the initialization code
  96.         // to use whatever heap size is given.
  97.             virtual long HeapNeeded            ( void )    { return 0; }
  98.     
  99.         // Loop control methods you may need to override
  100.             virtual void AdjustMenus        ( void )    {}                // menu updater routine
  101.             virtual void CleanUp            ( void )    {}                // run at end of loop
  102.             virtual void DoIdle                ( void )    {}                // idle time handler (blink caret, background tasks)
  103.             virtual void ExitLoop            ( void );                    // to end loop, call this routine
  104.             virtual void SetUp                ( void )    {}                // Run before event loop starts
  105.     
  106.         // event handlers you shouldn't need to override in a typical application
  107.             virtual void DoMouseInSysWindow    ( void )     { SystemClick(&fTheEvent, fWhichWindow); }
  108.             virtual void DoOSEvent            ( void );                    // Calls DoSuspend, DoResume and DoIdle as apropos
  109.             virtual void DoMouseDown        ( void );                    // Calls DoContent, DoGrow, DoZoom, etc
  110.             virtual void DoKeyDown            ( void );                    // also called for autokey events
  111.             virtual void DoActivateEvt        ( void );                    // handles setup, and calls DoActivate ( below)
  112.             virtual void DoGoAway            ( void );                    // handles setup, calls TDocument::DoClose
  113.             virtual void DoUpdateEvt        ( void );                    // handles setup, and calls DoUpdate ( below )
  114.             virtual void DoDrag                ( void );
  115.     
  116.         // handlers you will need to override for functionality:
  117.             // called by EventLoop and its handlers:
  118.                 virtual void AdjustCursor    ( void )    {}                // cursor adjust routine, should setup mouseRgn
  119.                 virtual void DoMenuCommand    ( short menuID, short menuItem )    { (void) menuID; (void) menuItem; /* avoid "not used" warning */}
  120.     
  121.             // called by OSEvent (just calls DoActivate by default, so no clip conversion
  122.             // is done). If you want to convert clipboard, override these routines
  123.                 virtual void DoSuspend(Boolean doClipConvert);
  124.                 virtual void DoResume(Boolean doClipConvert);
  125.         
  126.         // If you have an app that needs to know about these, override them
  127.             virtual void DoMouseUp( void ) {}
  128.             virtual void DoDiskEvt( void ) {}
  129.     
  130.         // Utility routines you need to provide to do MultiFinder stuff
  131.             virtual unsigned long SleepVal( void ) { return 0; }        // how long to sleep in WaitNextEvent
  132.  
  133.         // some other handy utility routines
  134.             // display alert, using specified error STR# resource and error code as index
  135.                 void AlertUser( short errResID, short errCode );
  136.             
  137.             // call AlertUser to display error message, then quit...
  138.                 void BigBadError( short errResID, short errCode );
  139.  
  140. }; /* class TApplication */
  141.  
  142. #endif
  143.